//
//  HS_ EssenceTableViewCell.m
//  悦享
//
//  Created by 韩双 on 16/3/24.
//  Copyright © 2016年 张洪国. All rights reserved.
//

#import "HS_EssenceTableViewCell.h"
#import <UIImageView+WebCache.h>

@interface HS_EssenceTableViewCell ()

@property (nonatomic, retain) UIImageView *photoImage;    /**< 图片 */
@property (nonatomic, retain) UILabel *titleLable;   /**< 内容Lable */
@property (nonatomic, retain) UILabel *timeLable;  /**< 时间Lable */

@end

@implementation HS_EssenceTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        [self createSubviews];
        
    }
    return self;
    
}

- (void)createSubviews {
    
    self.photoImage = [[UIImageView alloc] init];
    [self.contentView addSubview:_photoImage];
    
    self.titleLable = [[UILabel alloc] init];
    [self.contentView addSubview:_titleLable];
    
    self.timeLable = [[UILabel alloc] init];
    [self.contentView addSubview:_timeLable];
    
}

- (void)setModel:(HS_EssenceModel *)model {
    
    _model = model;
    
    [self assignment];
    
}

- (void)assignment {
    
    [_photoImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(SREEN_WIDTH / 3);
        make.top.equalTo(self.contentView).with.offset(5);
        make.bottom.equalTo(self.contentView).with.offset(-5);
        make.left.equalTo(self.contentView).with.offset(10);
        
    }];
    [_photoImage sd_setImageWithURL:[NSURL URLWithString:_model.image_url] placeholderImage:[UIImage imageNamed:PLACE_HLODER]];
    _photoImage.backgroundColor = [UIColor redColor];
    
    [_titleLable mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(_photoImage.mas_right).with.offset(10);
        make.top.equalTo(self.contentView).with.offset(5);
        make.right.equalTo(self.contentView).with.offset(-10);
        make.bottom.equalTo(self.contentView).with.offset(-50);

    }];
    _titleLable.numberOfLines = 3;
    _titleLable.font = [UIFont systemFontOfSize:15];
    _titleLable.textAlignment = NSTextAlignmentNatural;
    _titleLable.text = _model.title;
    
    [_timeLable mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.bottom.mas_equalTo(self.contentView).with.offset(-5);
        make.right.mas_equalTo(self.contentView).with.offset(-10);
        make.size.mas_equalTo(CGSizeMake(50, 10));

    }];
//    2016-03-24 18:29
    _timeLable.font = [UIFont systemFontOfSize:12];
    _timeLable.textAlignment = NSTextAlignmentRight;
    _timeLable.textColor = [UIColor lightGrayColor];
    _timeLable.text = [_model.datetime substringWithRange:NSMakeRange(6, 5)];
    
}




- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
